<?
if (!defined('SMF'))
	die('Hacking attempt...');

global $smcFunc, $txt, $scripturl, $settings;
global $dbtables;

/*
	Verify user login, update player info
	Check if CheckLogin() returned false return to the calling script/function
*/
$playerinfo = CheckLogin();
if ($playerinfo == false)
	return;

bigtitle($txt['bnt_sdf_title']);

$result = $smcFunc['db_query']('', '
	SELECT *
	FROM {raw:db_sector_defence}
	WHERE ship_id = {int:ship_id}',
	array(
		'db_sector_defence' => $dbtables['sector_defence'],
		'ship_id' => $playerinfo['ship_id'],
	)
);

$i = 0;

while ($sector[$i] = $smcFunc['db_fetch_assoc']($result))
{
	$i++;
}
$smcFunc['db_free_result']($result);

$num_sectors = $i;

if ($num_sectors < 1)
	echo '
	<p>', $txt['bnt_sdf_none'], '</p>';
else
{
	echo '
	<script type="text/javascript">
		$(document).ready(function(){
			// Table sorting function
			$(".bnt_table").tablesorter({
				widgets: ["zebra"]
			});
		});
	</script>
	<table class="bnt_table">
		<thead>
			<tr>
				<th>', $txt['bnt_sector'], '</td>
				<th>', $txt['bnt_qty'], '</td>
				<th>', $txt['bnt_sdf_type'], '</td>
				<th>', $txt['bnt_sdf_mode'], '</td>
			</tr>
		</thead>
		<tbody>';
	
	for ($i = 0; $i < $num_sectors; $i++)
	{
		echo '
			<tr>
				<td><a class="rs_link" href="#">', $sector[$i]['sector_id'], '</a></td>
				<td>', Number($sector[$i]['quantity']), '</td>';
		
		$defence_type = $sector[$i]['defence_type'] == 'F' ? $txt['bnt_fighters'] : $txt['bnt_mines'];
		
		echo '
				<td>', $defence_type, '</td>';
			
		$mode = $sector[$i]['defence_type'] == 'F' ? $sector[$i]['fm_setting'] : $txt['bnt_n_a'];
		
		if ($mode == 'attack')
			$mode = $txt['bnt_md_attack'];
		else
			$mode = $txt['bnt_md_toll'];
			
		echo '
				<td>', $mode, '</td>
			</tr>';
	}
	
	echo '
		</tbody>
	</table>';
}
?>
